<template>
    <!-- 新增和修改 -->
    <div class="modal fade" id="addhealthtalk" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">
                {{modaltitle}}</h4>
                </div>
                <div class="fail cbafter" v-show="healthtalksavedata.verifyState=='2'">
                    <div class="textdes">
                        <p class="nosuccess">审核未通过！</p>
                        <p>{{healthtalksavedata.verifySuggestion}}</p>
                    </div>
                </div>
                <div class="changeinfo cbafter">
                    <div class="changeinfo_head cbafter">
                        <span>申请人：{{username}}</span>
                        <span>申请时间：{{applytime}}</span>
                    </div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form" id="changedocform" v-on:submit.prevent="addhealthtalksave">
                        <div class="form-group">
                            <label class="col-md-3 control-label">讲座标题 :</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control" v-model="healthtalksavedata.lectureTitle" required />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">主讲医生 :</label>
                            <!-- <div class="col-md-8">
                                <input type="text" class="form-control" v-model="healthtalksavedata.lectureSayerName" required />
                            </div> -->
                            <div class="col-md-8">
                                <div id="zhuguanyis">
                                    <input type="hidden" class="form-control" placeholder="" v-model="healthtalksavedata.lectureSayer" />
                                    <input type="text" class="form-control" v-model="healthtalksavedata.lectureSayerName" required />
                                    <div class="yishenglist">
                                        <p @click="mayclick()">清空搜索内容</p>
                                        <p @click="mayclick(item,$event)" v-for="item in  expertlist | filterBy healthtalksavedata.lectureSayerName in 'name'">{{item.name}}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">医生职称 :</label>
                            <div class="col-md-8">
                                <!-- <select class="form-control" v-model="healthtalksavedata.level" required>
                                    <option v-for="item in doclevellist" value="{{item.key}}">{{item.text}}</option>
                                </select> -->
                                <input type="hidden" class="form-control" v-model="healthtalksavedata.level" readonly />
                                <input type="text" class="form-control" v-model="doctorJobTiyle" readonly />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">开始时间 :</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control" id="start" v-model="healthtalksavedata.lectureBeginTime" required />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">结束时间 :</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control" id="end" v-model="healthtalksavedata.lectureEndTime" required />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">讲座地点 :</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control" v-model="healthtalksavedata.lectureAddr" required />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">讲座内容 :</label>
                            <div class="col-md-8">
                                <textarea class="form-control" rows="3" placeholder="请输入讲座内容" v-model="healthtalksavedata.lectureContent" required></textarea>
                            </div>
                        </div>
                        <div class="form-group save">
                            <button type="submit" class="default ok center">确认</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import Public from 'assets/public.js'
import FileUploadBtn from 'components/FileUploadBtn.vue'
import 'assets/lib/laydate/laydate.js'
import 'assets/lib/laydate/need/laydate.css'
import 'assets/lib/laydate/skins/danlan/laydate.css'
module.exports = {
    data() {
            return {
                healthtalksavedata: {
                    "lectureAddr": "",
                    "lectureAttachFile": 0,
                    "lectureBeginTime": "",
                    "lectureEndTime": "",
                    "lectureSayer": '',
                    "lectureSayerName": "",
                    "lectureTitle": "",
                    level: "",
                    lectureContent: ""
                },
                doclevellist: [], //医生职称列表，
                //医生-专家列表
                expertlist: [],
                //医生职称
                doctorJobTiyle: ''
            }
        },
        components: {
            FileUploadBtn
        },
        props: {
            "username": {
                type: String,
                default: ""
            },
            "applytime": {
                type: String,
                default: ""
            },
            "imgurl": {
                type: String,
                default: ""
            },
            "uploadfilename": {
                type: String,
                default: ""
            },
            "modaltitle": {
                type: String,
                default: ""
            },

        },
        ready() {
            var that = this;
            // 获取医生职称字典
            // $.when(Public.commonajax("coms.multipleDictionaryService", "findDic", "[['base.dictionary.base_doctorTitle']]"))
            //     .done(function(res) {
            //         var data = res.body;
            //         that.doclevellist = data[0].items
            //     })
                // 日历插件
            laydate({
                elem: '#start',
                format: 'YYYY-MM-DD hh:mm:ss',
                min: laydate.now(),
                istime: true,
                choose: function(datas) { //选择日期完毕的回调
                    that.healthtalksavedata.lectureBeginTime = datas
                }
            });
            laydate({
                elem: '#end',
                format: 'YYYY-MM-DD hh:mm:ss',
                istime: true,
                min: laydate.now(),
                choose: function(datas) { //选择日期完毕的回调
                    that.healthtalksavedata.lectureEndTime = datas
                }
            });
            // 获取互动专家列表
            $.when(Public.commonajax("coms.doctorService", "queryDoctorByDoctorName", "[[]]"))
                .done(function(res) {
                    that.expertlist = res.body
            })
        },
        methods: {
            //新增和修改弹框
            addhealthtalk(item) {
                    $("#addhealthtalk").modal("show");
                    if (item) {
                        this.username = item.infoApplyUserName;
                        this.applytime = item.infoApplyTime;
                        this.healthtalksavedata = item;
                        this.imgurl = Public.FILEDOWNLOAD_URL() + item.lectureAttachFile;
                        this.uploadfilename = item.fileName;
                        this.modaltitle = "修改健康讲座";

                    } else {
                        this.username = sessionStorage.getItem('userName');
                        this.modaltitle = "新增健康讲座";
                        this.uploadfilename = "";
                        this.imgurl = "";
                        $("#imgupload").find('a').addClass('none');
                        this.healthtalksavedata = {
                            "lectureAddr": "",
                            "lectureAttachFile": 0,
                            "lectureBeginTime": "",
                            "lectureEndTime": "",
                            "lectureSayerName": "",
                            "lectureTitle": ""
                        };
                        var d = new Date(); //获取今天日期
                        var year = d.getFullYear();
                        var month = d.getMonth() + 1;
                        var date = d.getDate();
                        var hour = d.getHours();
                        var minute = d.getMinutes();
                        var second = d.getSeconds();
                        this.applytime = year + "-" + (month < 10 ? '0' + month : month) + "-" + (date < 10 ? '0' + date : date) + "   " + (hour < 10 ? '0' + hour : hour) + ":" + (minute < 10 ? '0' + minute : minute) + ":" + (second < 10 ? '0' + second : second);
                    }
            },

            //新增和修改保存
            addhealthtalksave() {
                var that = this;
                // if(healthtalksavedata.lectureAttachFile){
                //    Public.ajaxPrompt("请上传ppt");
                //    return
                // }
                let stringbegintime1 = that.healthtalksavedata.lectureBeginTime;
                let stringbegintime2 = that.healthtalksavedata.lectureEndTime;
                let begintime = stringbegintime1.substring(0, 10);
                let endtime = stringbegintime2.substring(0, 10);
                if (begintime != endtime) {
                    Public.ajaxPrompt("起始和结束日期请选择同一天");
                    return
                }
                let begintimecuo =  Date.parse(new Date(stringbegintime1));
                let endtimecuo = Date.parse(new Date(stringbegintime2));


                if (begintimecuo > endtimecuo) {
                    Public.ajaxPrompt("起始日期不能大于结束日期");
                    return
                }
                $.when(Public.commonajax("coms.healthLecturesService", "saveHealthLectures", "[" + JSON.stringify(this.healthtalksavedata) + "]"))
                    .done(function(res) {
                        if (res.code == 200) {
                            Public.ajaxPrompt("提交成功");
                            $("#addhealthtalk").modal("hide");

                            that.$dispatch('healthtalksave');
                        }

                    })
            },

            // 搜索医生下拉框选中后赋值给input
            mayclick(item, event) {
                if (item) {
                    this.healthtalksavedata.lectureSayerName = item.name;
                    this.healthtalksavedata.lectureSayer = item.doctorId;
                    this.healthtalksavedata.level = item.level;
                    this.doctorJobTiyle = item.levelText;

                } else {
                    this.healthtalksavedata.lectureSayerName = "";
                    this.healthtalksavedata.lectureSayer = "";
                    this.healthtalksavedata.level = "";
                    this.doctorJobTiyle = "";
                }
                $(".yishenglist").hide();
            }
        },
        events: {

            //上传文件返回的数据
            'servicefileId' (data) {
                this.healthtalksavedata.lectureAttachFile = data
            },


        },
}
$(function() {
    // 搜索位置主管医生的下拉
    $("#zhuguanyis").find('input').on('click', function(event) {
        event.preventDefault();
        $(".yishenglist").show();
    });
})
</script>
<style scoped>
#zhuguanyis {
    width: 100%;
    position: relative;
    display: inline-block;
}

#zhuguanyis .yishenglist {
    position: absolute;
    display: none;
    top: 32px;
    z-index: 9;
    width: 172px;
    height: 200px;
    overflow: auto;
    -webkit-box-shadow: 0 0 10px rgba(230, 230, 230, .9);
    -moz-box-shadow: 0 0 10px rgba(230, 230, 230, .9);
    box-shadow: 0 0 10px rgba(230, 230, 230, .9);
    background: #fff;
    border-radius: 0 0 10px 10px;
    padding: 10px
}

#zhuguanyis .yishenglist p {
    line-height: 26px;
    height: 26px;
    margin-top: 5px;
    background: #f1f1f1;
    padding-left: 10px;
    padding-top: 0;
}

#zhuguanyis .yishenglist p:nth-child(1) {
    background: #1dc499;
    color: #fff
}
</style>
